package com.example.light.system.controller;

import com.example.light.system.common.Result;
import com.example.light.system.entity.announcement;
import com.example.light.system.entity.loginLog;
import com.example.light.system.entity.systemLog;
import com.example.light.system.service.impl.ILoginLogService;
import com.example.light.system.service.impl.ISystemLogService;
import com.example.light.system.vo.insertLoginLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.UnknownHostException;
import java.util.List;

@Api(description = "日志文件接口")
@RestController
@RequestMapping("/LogFile")
public class LogController {
    @Resource
    ILoginLogService iLoginLogService;
    @Resource
    ISystemLogService iSystemLogService;

    @ApiOperation("测试接口:通过id查找对应日志文件")
    @PostMapping("/searchById")
    public Result<loginLog> searchById(int id){
        return iLoginLogService.searchLoginFile(id);
    }

    @ApiOperation("新增登录信息")
    @PostMapping("/insertLogLogin")
    public Result<loginLog> insertLoginLog(@RequestBody insertLoginLog insertLoginLog) throws UnknownHostException{
        return iLoginLogService.insertLoginLog(insertLoginLog);
    }

    @ApiOperation("获取客户端ip")
    @PostMapping("/getClientIpAddress")
    public String getClientIpAddress(HttpServletRequest request){
        return iLoginLogService.getClientIpAddress(request);
    }

    @ApiOperation("获取系统日志")
    @PostMapping("/getSystemLog")
    public Result<systemLog> getSystemLog() throws InterruptedException{
        return iSystemLogService.getSystemLog();
    }

    @ApiOperation("新增系统公告")
    @PostMapping("/addAnnouncement")
    public Result<String> addAnnouncement(String deviceName, Integer type){
        return iSystemLogService.addAnnouncement(deviceName, type);
    }

    @ApiOperation("获取未读系统公告信息")
    @PostMapping("/getAnnouncement")
    public Result<List<announcement>> getAnnouncement(){
        return iSystemLogService.getAnnouncement();
    }

    @ApiOperation("获取已读系统公告信息")
    @PostMapping("/getReadAnnouncement")
    public Result<List<announcement>> getReadAnnouncement(){
        return iSystemLogService.getReadAnnouncement();
    }

    @ApiOperation("获取逻辑删除系统公告信息")
    @PostMapping("/getDeleteAnnouncement")
    public Result<List<announcement>> getDeleteAnnouncement(){
        return iSystemLogService.getDeleteAnnouncement();
    }

    @ApiOperation("标记系统公告为已读")
    @PostMapping("/markRead")
    public Result<String> markRead(String uuid){
        return iSystemLogService.markRead(uuid);
    }

    @ApiOperation("标记系统公告为删除")
    @PostMapping("/markDelete")
    public Result<String> markDelete(String uuid){
        return iSystemLogService.markDelete(uuid);
    }

    @ApiOperation("删除系统公告信息")
    @PostMapping("/DeleteAnnouncement")
    public Result<String> DeleteAnnouncement(String uuid){
        return iSystemLogService.DeleteAnnouncement(uuid);
    }

    @ApiOperation("还原系统公告")
    @PostMapping("/restore")
    public Result<String> restore(String uuid){
        return iSystemLogService.restore(uuid);
    }

}
